<style lang="scss" scoped>
@import "@/assets/css/variable";
.activityShow {
  width: 100%;
  // top: 0;
  // left: 0;
  // bottom: 0;
  // right: 0;
  // height: 1500px;
  padding-bottom: 6.2rem;
  background-color: #f7f8fa;
  min-height: 100%;
  font-size: 1.2rem;
  box-sizing: border-box;
  position: relative;
  flex: 1;
  overflow: hidden;
  // $radiusSize: 100%;
  display: flex;
  flex-direction: column;
  .sweips {
    width: 100%;
    height: 20rem;
    img {
      height: 20rem;
    }
  }
  .exothecium {
    display: flex;
    width: 100%;
    height: 9rem;
    .exothecium_left {
      display: flex;
      width: 53%;
      height: 100%;
      background-color: var(--theme_color);
      position: relative;
      //  box-shadow: 3px 0 3px rgba(0, 0, 0, .11);
      .dumpling {
        width: 7.6rem;
        height: 2rem;
        line-height: 2rem;
        text-align: center;
        margin-top: 1.4rem;
        border-radius: 0 10px 10px 0;
        background-color: #fff;
        color: var(--theme_color);
        font-size: 1.3rem;
      }
      .price {
        display: flex;
        flex-direction: column;
        padding-left: 1.5rem;
        color: #fff;
        .price_number {
          margin-top: 1.2rem;
          margin-bottom: 0.8rem;
          font-weight: 600;
          font-size: 1.8rem;
        }
      }
      .triangle_border {
        width: 0;
        height: 0;
        border-bottom: 9rem solid var(--theme_color);
        border-right: 3rem solid transparent;
        position: absolute;
        left: 100%;
      }
    }
    .exothecium_right1 {
      box-sizing: border-box;
      width: 47%;
      height: 100%;
      display: flex;
      align-content: center;
      justify-content: center;
      padding-top: 10%;
      font-size: 15px;
      color: #333;
    }
    .exothecium_right {
      width: 47%;
      height: 100%;
      display: flex;
      flex-direction: column;
      background-color: #faeee2;
      .text {
        margin: 1rem 0 1rem 7rem;
      }
      .out_time {
        margin-left: 3rem;
        span {
          display: inline-block;
          padding: 0 0.2rem;
          // width: 1.5rem;
          // height: 1.5rem;
          background-color: #3b3b3b;
          color: #fff;
          line-height: 1.5rem;
          text-align: center;
          font-size: 0.8rem;
        }
      }
    }
  }

  .conter {
    display: flex;
    box-sizing: border-box;
    width: 100%;
    // height: 13rem;
    margin-top: -10px;
    background-color: #fff;
    border-radius: 10px;
    position: relative;
    z-index: 2;
    padding: 2rem 1.6rem;
    .copy_writer {
      width: 80%;
      height: 100%;
      h3 {
        //  font-weight: 550;
        font-size: 1.8rem;
      }
      p {
        color: #999;
        margin-top: 1.5rem;
        font-size: 1.5rem;
        letter-spacing: 0.05rem;
        line-height: 2.5rem;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
      }
      div {
        margin-top: 1.5rem;
        font-size: 1.3rem;
        .shuxian {
          padding: 0 1.2rem;
          color: #999;
        }
      }
    }
    .share {
      box-sizing: border-box;
      display: flex;
      justify-content: flex-end;
      width: 20%;
      height: 100%;
      .share_btn {
        background-color: var(--btn_color);
        color: #fff;
        padding-left: 6px;
        padding-right: 6px;
      }
    }
  }

  .details {
    display: flex;
    flex-direction: column;
    box-sizing: border-box;
    width: 100%;
    margin-top: 1rem;
    background-color: #fff;
    border-radius: 10px;
    padding: 1.3rem 1.6rem 0;
    .text {
      color: #333;
      font-size: 1.3rem;
      margin-bottom: 10px;
      .icon {
        color: var(--theme_color);
        margin-right: 3px;
      }
    }
    .details_tuan {
      display: flex;
      justify-content: space-between;
      align-items: center;
      margin-bottom: 1rem;
      .details_wai {
        display: flex;
        align-items: center;
        .details_neione {
          margin-right: 0.3rem;
          // .img {
          //   padding-right: 3px;
          // }
        }
        .details_neitwo {
          margin-left: 0.3rem;
          display: flex;
          flex-direction: column;
          justify-content: space-around;
          :first-child {
            margin-bottom: 4px;
          }
        }
      }
      .tuan_wai {
        background-color: var(--theme_color);
        color: #fff;
      }
    }
  }

  .activity {
    box-sizing: border-box;
    width: 100%;
    margin-top: 1rem;
    background-color: #fff;
    border-radius: 10px;
    padding: 2rem 1.6rem;
  }

  .tuan_button {
    position: fixed;
    bottom: 2rem;
    left: 50%;
    transform: translateX(-50%);
    width: 85%;
    height: 4rem;
    background: -webkit-linear-gradient(top, #f2f2f2, #fd8701);
    background-color: #fe7b58;
    border-radius: 4rem;
    line-height: 4rem;
    text-align: center;
    color: #fff;
    font-size: 1.7rem;
  }

  .show {
    height: auto;
    background-color: white;
    position: relative;
    .close-icon {
      position: absolute;
      width: 2.4rem;
      height: 2.4rem;
      right: 0.7rem;
      top: 0.7rem;
      border-radius: 1.2rem;
      display: flex;
      align-items: center;
      justify-content: center;
      z-index: 2;
    }
    img {
      width: 100%;
    }
    .posterHtml {
      // display: flex;
      #coverImg {
        display: flex;
        width: 100%;
        max-height: 30rem;
        object-fit: cover;
      }
      .imgBox {
        width: 100%;
      }
      .content {
        padding: 1.2rem;
        display: flex;
        height: 14rem;
        justify-content: space-between;
        .desc {
          word-wrap: break-word;
          display: flex;
          flex-direction: column;
          justify-content: space-around;
          height: 100%;
          .line1 {
            font-size: 2rem;
            font-weight: bold;
            color: #333;
            display: flex;
            align-items: center;
          }
          .line2 {
            font-size: 2.2rem;
            font-weight: 900;
            color: #111;
            // overflow: hidden;
            // text-overflow: ellipsis;
            // display: -webkit-box;
            // -webkit-line-clamp:2; /* 设置行数 */
            // -webkit-box-orient:vertical;
          }
        }
        .qrcode {
        }
      }
      .bottom-box {
        padding-bottom: 2rem;
        padding-left: 1.2rem;
        padding-right: 1.2rem;
      }
    }
  }

  .imgBox {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background-color: rgba($color: #000000, $alpha: 0.98);
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 3000;
    img {
      width: 100%;
    }
    .tips {
      color: white;
    }
    .close-icon {
      position: fixed;
      width: 2.4rem;
      height: 2.4rem;
      right: 0.7rem;
      top: 0.7rem;
      border-radius: 1.2rem;
      display: flex;
      align-items: center;
      justify-content: center;
      z-index: 3002;
    }
  }

  .navigation {
    position: fixed;
    box-sizing: border-box;
    bottom: 10rem;
    right: 1rem;
    // width: 5rem;
    background-color: var(--btn_color);
    text-align: center;
    color: #fff;
    font-size: 1.2rem;
    border-radius: 3px;
    z-index: 22;
    .my_tuan {
      box-sizing: border-box;
      width: 100%;
      height: 3rem;
      padding: 0 0.5rem;
      line-height: 3rem;
      border-bottom: 1px solid #fff;
    }
  }
  .fix-bottom {
    display: flex;
    overflow: hidden;
    position: fixed;
    bottom: 1rem;
    left: 0;
    right: 0;
    width: 100%;
    z-index: 3;
    box-sizing: border-box;
  }

  .dwon_btn {
    .tuan_btn {
      background-color: var(--btn_color);
      border-radius: 8px;
      // box-shadow: 1px 1px 2px #555555;
      color: #fff;
      font-size: 1.2rem;
      letter-spacing: 1rem;
      border: 0;
    }
    .release_btn1 {
      background-color: var(--btn_color);
      margin-right: 15px;
      border-radius: 8px;
      font-size: 1.2rem;
      letter-spacing: 0.5rem;
      color: #fff;
      border: 0;
    }
  }
}
</style>
<template>
  <div
    class="activityShow"
    :style="{ '--theme_color': theme_color, '--btn_color': btn_color }"
  >
    <music-play
      v-if="activityItem.music"
      :activityItem="activityItem"
    ></music-play>
    <van-skeleton :row="$store.state.skeletonRow" :loading="loadingSkeleton">
      <div class="sweips">
        <img :src="activityItem.cover" alt="" />
      </div>
      <div class="exothecium">
        <div class="exothecium_left">
          <div class="dumpling">
            <span>{{ val.group_num }}人团</span>
          </div>
          <div class="price">
            <span class="price_number">￥ {{ val.chief_price }}</span>
            <span>原价{{ val.price }}元</span>
          </div>
          <div class="triangle_border"></div>
        </div>
        <div class="exothecium_right" v-if="activityItem.end == 1">
          <div class="text">距离结束还剩</div>
          <div class="out_time">
            <span>{{ DD }}</span> 天 <span>{{ HH }}</span> ：
            <span>{{ MM }}</span> ：
            <span>{{ SS }}</span>
          </div>
        </div>
        <div class="exothecium_right1" v-if="activityItem.end == 2">
          <div>活动已结束</div>
        </div>
      </div>

      <div class="conter">
        <div class="copy_writer">
          <h3>{{ activityItem.sharetitle }}</h3>
          <p>{{ activityItem.share_describe }}</p>
          <div>
            <span>剩余可开团数 {{ val.group_surplus }}</span>
            <span class="shuxian">|</span>
            <span>已参与的人数 {{ activityItem.join_num }}</span>
          </div>
        </div>
        <div class="share">
          <van-button size="mini" round @click="shareBtn1" class="share_btn"
            >分享</van-button
          >
        </div>
      </div>

      <div class="details">
        <div class="text">
          <van-icon class="icon" name="fire" />
          {{ val.group_num }}人可成团，可直接参团
        </div>

        <div
          class="details_tuan"
          v-for="item in offeredList"
          :key="item.group_id"
        >
          <!-- v-if="item.nums != 3" -->
          <div class="details_wai">
            <div
              class="details_neione"
              v-for="(item1, i) in item.avatar_arr"
              :key="i"
              v-if="i < 3 ? true : false"
            >
              <van-image
                class="img"
                round
                width="2.4rem"
                height="2.4rem"
                :src="item1.avatar"
              />
            </div>
            <div class="details_neitwo">
              <span style="margin-bottom: 5px"
                >还差{{ item.nums }}人可成团</span
              >
              <span style="color: #999">剩余 {{ item.dayTime }}</span>
            </div>
          </div>
          <div>
            <van-button
              size="mini"
              round
              @click="offeredClick(item)"
              class="tuan_wai"
              >去参团</van-button
            >
          </div>
        </div>
      </div>

      <div class="activity">
        <div style="margin-bottom: 10px">
          <div style="font-size: 15px">活动时间</div>
          <div style="margin-top: 10px">
            {{ activityItem.start_time }} 至 {{ activityItem.end_time }}
          </div>
        </div>
        <div style="margin-bottom: 10px; font-size: 15px">活动介绍</div>
        <div v-for="item in introduce" :key="item.id">
          <van-image
            v-if="item.type == 'img'"
            width="200"
            height="200"
            :src="item.value"
          />
          <div
            style="margin-bottom: 10px"
            v-if="item.type == 'text'"
            v-html="item.value"
          ></div>
        </div>
      </div>

      <div class="fix-bottom padding-lr dwon_btn">
        <van-button
          size="normal"
          v-if="activityItem.act_release == 1"
          @click="releaseClick"
          class="release_btn1"
          block
          >创建活动</van-button
        >
        <!-- <a class="a_click"></a> -->
        <van-button size="normal" block @click="tuanClick" class="tuan_btn">
          {{ activityItems.status == 1 ? "立即开团" : "活动结束" }}</van-button
        >
      </div>
    </van-skeleton>
    <div class="navigation">
      <div class="my_tuan" @click="myGroup">我的团队</div>
      <div class="my_tuan" @click="orderGroup">我的订单</div>
      <div class="my_tuan" @click="envelopeGroup">红包排行</div>
      <div class="my_tuan" @click="wthdrawGroup">我的余额</div>
    </div>

    <!-- 商家信息 -->
    <div style="padding: 0 15px">
      <infor-mation :activityItem="activityItems"></infor-mation>
    </div>
    <!-- 分享蒙版 -->
    <share-mask v-if="cancelShow" @shareChange="shareChange" @cancelChange="cancelChange"></share-mask>

    <Footer :config="config"></Footer>

    <!-- <div class="tuan_button" @click="tuanClick">立即开团</div> -->

    <!-- 分享 -->
    <van-popup v-model="showPop" position="bottom" round>
      <div class="show">
        <span
          class="close-icon"
          :style="{ backgroundColor: theme_color }"
          @click="showPop = false"
          ><van-icon color="white" name="cross"
        /></span>
        <!-- 海报html元素 -->
        <div id="posterHtml" class="posterHtml">
          <img id="coverImg" :src="copyimg" />
          <div class="content">
            <div class="desc">
              <div class="line1">
                <span>快来参加</span>
                <van-icon class="margL-m" name="fire" :color="theme_color" />
              </div>
              <div class="line2">{{ activityItem.title }}</div>
            </div>
            <!-- 二维码 -->
            <canvas class="qrcode" id="qrCode-canvas"></canvas>
          </div>
          <div class="margT-l bottom-box">
            <div class="fs-16 t-bold">{{ activityItem.merchantname }}</div>
            <div class="color-m margT-m" style="display:flex; center;">
              <span></span>
              <span>本次活动 {{ activityItem.end_time }} 结束</span>
              <span></span>
            </div>
          </div>
        </div>
        <div class="padding-lr">
          <van-button
            :color="theme_color"
            block
            @click="createPoster"
            :loading="createLoading"
            >生成海报</van-button
          >
        </div>
      </div>
    </van-popup>
    <div class="imgBox" v-if="showImgPop">
      <img :src="createImg" />
      <div class="tips margT-m fs-16">Tips:长按以上海报即可保存或转发</div>
      <span
        class="close-icon"
        :style="{ backgroundColor: theme_color }"
        @click="showImgPop = false"
        ><van-icon color="white" name="cross"
      /></span>
    </div>
  </div>
</template>

<script>
import {
  Button,
  Toast,
  Tab,
  Tabs,
  Icon,
  Dialog,
  Popup,
  Image as VanImage,
  AddressEdit,
  AddressList,
  Skeleton,
} from "vant";
import QRCode from "qrcode";
import html2canvas from "html2canvas";
import Header from "@/components/headerlotto";
import MusicPlay from "@/components/MusicPlay";
import Footer from "@/components/Footer";
import InforMation from "@/components/InforMation";
import ShareMask from "@/components/ShareMask";
// import { areaList } from "@vant/area-data";
// import func from 'vue-editor-bridge';
import utils from "@/assets/js/utils.js";
// import { mapGetters } from 'vuex'
export default {
  name: "groupBuyingactivityShow",
  components: {
    [Tab.name]: Tab,
    [Tabs.name]: Tabs,
    [Button.name]: Button,
    [Icon.name]: Icon,
    [Dialog.name]: Dialog,
    [Popup.name]: Popup,
    [VanImage.name]: VanImage,
    [AddressEdit.name]: AddressEdit,
    [AddressList.name]: AddressList,
    [Skeleton.name]: Skeleton,
    Header,
    MusicPlay,
    Footer,
    InforMation,
    ShareMask
  },
  data() {
    return {
      loadingSkeleton: true,
      config: "",
      p_openid: "",
      is_apply: false,
      showPop: false,
      showImgPop: false,
      createLoading: false,
      id: "",
      createImg: "",
      config: "",
      activityItem: {},
      val: {},
      endtime: "",
      // tuanendtime: "",
      flag: false,
      openid: localStorage.getItem("COPENID"),
      DD: "00",
      HH: "00",
      MM: "00",
      SS: "00",
      IngroupList: [],
      introduce: [],
      create_form: {},
      offeredList: [],
      orderItem: {},
      is_apply: false,
      temp: null, //倒计时初始
      activity_id: null,
      theme_color: "",
      is_refund: false,
      is_withdrawal: false,
      copyimg: "",
      is_edit: 0,
      staff_id: null,
      activityItems: {},
      btn_color: "",
      domain: {},
      cancelShow: false,
    };
  },
  // computed: {
  //   getOpenId() {
  //     this.openid = this.$store.state.openid
  //     return this.openid
  //   }
  // },
  // computed:{
  //     ...mapGetters(['getActivityItem']),
  // },
  created() {
    this.activity_id = Number(this.$route.params.id);
    //获取炮灰域名并判断是否跳转到炮灰域名
    this.getDomain();
  },
  destroyed() {
    //需要销毁
    clearInterval(this.temp);
    console.log(this.temp, "销毁");
  },
  mounted() {
    const _this = this;
    let time = setInterval(() => {
      if (_this.flag == true) {
        clearInterval(time);
      }
      _this.timeDown();
    }, 1000);
    _this.staff_id = _this.$route.query.staff_id;
    _this.activityItem = _this.$store.state.activityItem;
    // 获取用户在后台管理系统中自定义的H5页面所显示的应用名称
    _this.ConfigItem();
  },
  methods: {
    //获取炮灰域名并判断是否跳转到炮灰域名
    getDomain() {
      const _this = this;
      if (process.env.NODE_ENV == "production") {
        _this.openid = localStorage.getItem("COPENID");
        if (
          _this.$route.query.openid &&
          _this.$route.query.openid != "undefined"
        ) {
          _this.openid = _this.$route.query.openid;
          localStorage.setItem("COPENID", _this.openid);
        }
      } else {
        _this.openid = _this.$store.state.openid;
      }
      let params = {};
      _this.$request.getDomain(params).then((res) => {
        if (res.ret == 200) {
          if (res.data.value.mainUrl && res.data.value.cannonUrl) {
            let domain = {
              mainUrl: res.data.value.mainUrl,
              cannonUrl: res.data.value.cannonUrl,
            };
            _this.domain = domain;

            console.log(
              "cannonUrl:" + location.href.indexOf(_this.domain.cannonUrl)
            );
            if (location.href.indexOf(_this.domain.cannonUrl) > -1) {
              _this.openid = _this.$route.query.openid;
              localStorage.setItem("COPENID", _this.openid);
              console.log("cannonUrl_this.openid", _this.openid);
            }
            //openid没拿到的时候
            if (!_this.openid || _this.openid == "undefined") {
              //当前为炮灰域名的时候
              if (location.href.indexOf(_this.domain.cannonUrl) > -1) {
                //跳转到主域名
                window.location.href = `${_this.domain.mainUrl}${
                  location.href.indexOf("addons") > -1
                    ? "/addons/youmi_activitys/public"
                    : ""
                }/plugin/index.html#/caseShow/groupBuying/activityShow/${Number(
                  _this.$route.params.id
                )}?staff_id=${_this.$route.query.staff_id}&p_openid=${
                  _this.$route.query.p_openid
                }`;
                return;
              }
            } else {
              _this.toCannonUrl();
            }
          }

          console.log("_this.openid:" + _this.openid);
          if (!_this.openid || _this.openid == "undefined") {
            _this.getWeixinConfig(); // 通过微信授权 获取 openID
          } else {
            _this.getPageActItem();
            //_this.getActivityItem(); // 获取活动数据的同时会调用getOrderItem、shareInit函数是、
          }
        }
      });
    },
    toCannonUrl() {
      const _this = this;
      if (location.href.indexOf(_this.domain.mainUrl) > -1) {
        //跳转到炮灰域名
        window.location.href = `${_this.domain.cannonUrl}${
          location.href.indexOf("addons") > -1
            ? "/addons/youmi_activitys/public"
            : ""
        }/plugin/index.html#/caseShow/groupBuying/activityShow/${Number(
          _this.$route.params.id
        )}?staff_id=${_this.$route.query.staff_id}&p_openid=${
          _this.$route.query.p_openid
        }&openid=${_this.openid}`;
      }
    },
    // 分享按钮
    shareBtn1() {
      this.cancelShow = true;
    },
    // 取消按钮
    cancelChange() {
      this.cancelShow = false;
    },
    // 生成海报
    shareChange() {
      this.cancelShow = false;
      this.shareBtn();
    },

    getActivityItem() {
      let params = {
        id: Number(this.$route.params.id),
      };
      this.$request.getActivityItem(params).then((res) => {
        this.activityItems = res.data;
        this.btn_color = res.data.btn_color;
        this.getMerchantItem(this.activityItems.merchant_id);
      });
    },
    // 跳转我也要发布活动
    releaseClick() {
      window.location.href = `//${location.hostname}${
        location.href.indexOf("addons") > -1
          ? "/addons/youmi_activitys/public"
          : ""
      }/mobile/index.html#/case/${this.activityItem.model}/${
        this.activityItem.id
      }?is_edit=${this.is_edit}&case_id=${this.activityItem.case_id}`;
    },
    // 我的团队
    myGroup() {
      // this.$store.commit("setActivityItem", this.activityItem);
      // this.$store.commit("setThemeColor", this.theme_color);
      this.$router.push(
        `/caseShow/groupBuying/GroupMy?activity_id=${this.activity_id}&theme_color=${this.theme_color}`
      );
    },

    // 点击我的订单
    orderGroup() {
      // this.$store.commit("setActivityItem", this.activityItem);
      // this.$store.commit("setThemeColor", this.theme_color);
      this.is_refund = this.val.is_refund;
      this.$router.push(
        `/caseShow/groupBuying/GroupOrder?activity_id=${this.activity_id}&is_refund=${this.is_refund}&theme_color=${this.theme_color}`
      );
    },

    // 点击红包列表
    envelopeGroup() {
      // this.$store.commit("setActivityItem", this.activityItem);
      // this.$store.commit("setThemeColor", this.theme_color);
      this.$router.push(
        `/caseShow/groupBuying/GroupEnvelope?activity_id=${this.activity_id}&theme_color=${this.theme_color}`
      );
    },

    // 点击零钱
    wthdrawGroup() {
      // console.log(this.activity_id);
      // this.$store.commit("setThemeColor", this.theme_color);
      this.is_withdrawal = this.val.is_withdrawal;
      this.$router.push(
        `/caseShow/money/WithdrawDeposit?activity_id=${this.activity_id}&is_withdrawal=${this.is_withdrawal}&theme_color=${this.theme_color}`
      );
    },
    timer(time) {
      //页面多个定时器
      this.temp = setInterval(() => {
        time.forEach((item, index) => {
          const endTime = new Date(item.endtime).getTime();
          item.dayTime = utils.countDownFun(endTime);
          // this.$set(time,item.dayTime, countDownFun(item.endtime))
          // console.log(this.temp, '6')
        });
      }, 1000);
    },

    // 立即参团
    offeredClick(item) {
      console.log(item, "openid");
      // if(item.openid == localStorage.getItem("COPENID") ) return Toast('不能参加自己的团')
      this.$store.commit("setOfferedItem", item);
      this.$router.push(
        `/caseShow/groupBuying/applyForm?activity_id=${this.activity_id}&staff_id=${this.staff_id}&theme_color=${this.theme_color}`
      );
    },

    // 查询参团
    getInGroup() {
      let params = {
        activity_id: Number(this.$route.params.id),
      };
      this.$request.getInGroup(params).then((res) => {
        this.offeredList = res.data.data;
        this.timer(this.offeredList);
      });
    },
    // 我要开团
    tuanClick() {
      this.$store.commit("setOfferedItem", {});
      this.$store.commit("setThemeColor", this.theme_color);
      if (this.activityItems.status == 2) return this.$toast("活动已结束");
      this.getInGroup();
      this.$router.push(
        `/caseShow/groupBuying/applyForm?activity_id=${this.activity_id}&staff_id=${this.staff_id}`
      );
      //  this.$router.push('/caseShow/groupBuying/ApplyForm')
      //  this.$router.push('/caseShow/groupBuying/groupDetails')
    },
    // shareClick() {
    //   this.showPop = true;
    // },

    // 分享
    helpTimes(activityItem) {
      const _this = this;
      console.log("_this.$route.query.p_openid", _this.$route.query.p_openid);
      const p_openid = _this.$route.query.p_openid;
      if (p_openid) {
        let params = {
          activity_id: _this.activity_id,
          openid: _this.openid,
          p_openid: p_openid,
        };
        console.log(p_openid, "p_openid");
        _this.$request.receivingHelp(params).then((res) => {});
      }
    },
    // applyClick() {
    //   this.$router.push(`/caseShow/groupBuying/applyForm`);
    // },
    ConfigItem() {
      const _this = this;
      let params = {};
      _this.$request.ConfigItem(params).then((res) => {
        _this.config = res.data.value;
        console.log("_this.config", _this.config);
      });
    },
    shareInit(activityItem) {
      const _this = this;
      const url = location.href.split("#")[0];
      let params = {
        url: url,
      };
      _this.$request.configJssdk(params).then((res) => {
        wx.config({
          debug: false, // 是否开启调试模式
          appId: res.data.appId, //appid
          timestamp: res.data.timestamp, // 时间戳
          nonceStr: res.data.nonceStr, // 随机字符串
          signature: res.data.signature, // 签名
          jsApiList: [
            "checkJsApi",
            "updateAppMessageShareData",
            "updateTimelineShareData",
          ], // 需要使用的JS接口列表
        });
        let link = "";
        if (location.href.indexOf("staff_id") > -1) {
          link = location.href;
        } else {
          link = `${location.href}?staff_id=${this.staff_id}`;
        }
        const dataShare = {
          title: activityItem.sharetitle,
          desc: activityItem.share_describe, // 分享描述
          link: link, // 分享链接，该链接域名或路径必须与当前页面对应的公众号JS安全域名一致
          imgUrl: activityItem.shareimg, // 分享图标
          success: function () {
            // 设置成功
          },
          fail: function (error) {
            // alert(JSON.stringify(error))
          },
        };
        wx.updateAppMessageShareData(dataShare);
        wx.updateTimelineShareData(dataShare);
        wx.error(function (error) {
          // alert(JSON.stringify(error))
        });
      });
    },
    toTop() {
      let top = document.documentElement.scrollTop || document.body.scrollTop;
      // 实现滚动效果
      const timeTop = setInterval(() => {
        document.body.scrollTop =
          document.documentElement.scrollTop =
          top -=
            50;
        if (top <= 0) {
          clearInterval(timeTop);
        }
      }, 10);
    },
    shareBtn() {
      this.toTop();
      const _this = this;
      let params = {
        id: _this.activity_id,
      };
      _this.$request.getActivityItembase64(params).then((res) => {
        _this.copyimg = res.data;
      });
      _this.showPop = true;
      _this.$nextTick(function () {
        _this.createQrcode();
      });
    },
    createPoster() {
      // 生成海报
      const vm = this;
      vm.createLoading = true;
      const domObj = document.getElementById("posterHtml");
      html2canvas(domObj, {
        useCORS: true,
        allowTaint: true,
        logging: true,
        letterRendering: true,
        onclone(doc) {
          let e = doc.querySelector("#posterHtml");
          e.style.display = "block";
        },
      }).then(function (canvas) {
        // 在微信里,可长按保存或转发
        // let url = canvas.toDataURL('image/png')
        // const a = document.createElement('a'); // 创建a标签
        // a.setAttribute('download', `${new Date().getTime()}.png`);// download属性
        // a.setAttribute('href', url);// href链接
        // a.click();// 自执行点击事件
        let url = canvas.toDataURL("image/png");
        vm.createImg = url;
        vm.showImgPop = true;
        vm.createLoading = false;
        vm.showPop = false;
      });
    },
    createQrcode() {
      const _this = this;
      let href = `${location.protocol}//${location.hostname}${
        location.href.indexOf("addons") > -1
          ? "/addons/youmi_activitys/public"
          : ""
      }/plugin/index.html#/caseShow/${this.activityItem.model}/activityShow/${
        this.activityItem.activitys_id
      }?staff_id=${this.staff_id}`;
      // _this.activityItem = _this.getActivityItem
      // console.log('_this.activityItem.activitys_id',_this.activityItem.activitys_id)
      // let href = ''
      // //先去判断是否设置了炮灰域名
      // if(_this.domain.cannonUrl) {
      // 		  href = `http://${_this.domain.cannonUrl}${
      // 		    location.href.indexOf("addons") > -1
      // 		      ? "/addons/youmi_activitys/public"
      // 		      : ""
      // 		  }/plugin/index.html#/caseShow/${_this.activityItem.model}/activityShow/${
      // 		    _this.activityItem.activitys_id
      // 		  }?staff_id=${_this.staff_id}&p_openid=${_this.openid}`;
      // }else{
      // 		  href = `${location.protocol}//${location.hostname}${
      // 		    location.href.indexOf("addons") > -1
      // 		      ? "/addons/youmi_activitys/public"
      // 		      : ""
      // 		  }/plugin/index.html#/caseShow/${_this.activityItem.model}/activityShow/${
      // 		    _this.activityItem.activitys_id
      // 		  }?staff_id=${_this.staff_id}&p_openid=${_this.openid}`;
      // }
      let canvas = document.getElementById("qrCode-canvas");
      QRCode.toCanvas(canvas, href, (error) => {
        if (error) {
          console.log(error);
        } else {
          canvas.style.width = "12rem";
          canvas.style.height = "12rem";
          // _this.createPoster()
        }
      });
    },
    // 获取该活动的订单信息
    getOrderItem() {
      const _this = this;

      let params = {
        openid: _this.openid,
        activity_id: Number(this.$route.params.id),
      };
      _this.$request.getOrderItem(params).then((res) => {
        const orderItem = res.data;
        if (orderItem.openid == this.openid) {
          _this.is_apply = true;
        }
        console.log("-----orderItem-----", orderItem.status);
        _this.$store.commit("setOrderItem", orderItem);
        // 获取订单列表，并判断是否有自己的订单
        // let orderList = res.data.val
        // console.log('-----orderList-----',orderList)
        // orderList.forEach(item=>{
        // 	if(item.openid==_this.openid){
        // 		_this.is_apply = true
        // 	}
        // })
        //      if(res.data.val&&res.data.val!=null&&res.data.val.length>0){

        //        _this.is_apply = true
        //      }
      });
    },
    getWeixinConfig() {
      const _this = this;
      let params = {};
      _this.$request.getWeixinConfig(params).then((res) => {
        _this.$store.commit("setAppid", res.data.value.appid);
        _this.$store.commit("setSecret", res.data.value.secret);
        //_this.getCode(res.data.value.appid)
        _this.getCode(res.data.value.appid);
      });
    },
    getCode(appid) {
      // 非静默授权，第一次有弹框
      const _this = this;
      const code = this.getUrlParam("code"); // 截取路径中的code，如果没有就去微信授权，如果已经获取到了就直接传code给后台获取openId
      const local = window.location.href;
      if (code == null || code === "") {
        window.location.href =
          "https://open.weixin.qq.com/connect/oauth2/authorize?appid=" +
          appid +
          "&redirect_uri=" +
          encodeURIComponent(local) +
          "&response_type=code&scope=snsapi_userinfo&state=1#wechat_redirect";
      } else {
        _this.$store.commit("setCode", code);
        _this.getOpenId(code); //把code传给后台获取用户信息
      }
    },
    getUrlParam(name) {
      var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
      var r = window.location.search.substr(1).match(reg);
      if (r != null) return unescape(r[2]);
      return null;
    },
    getFansItem(item) {
      console.log("fansItem:", item);
      const _this = this;
      let params = {
        openid: item.openid || _this.openid,
        nickname: item.nickname,
        name: item.nickname,
        avatar: item.avatar,
        province: item.province,
        city: item.city,
      };
      console.log("item.openid", item.openid);
      console.log("fansItem:", item);
      _this.$request.getFansItem(params).then((res) => {
        // 默认
        // _this.getOrderItem();
      });
    },
    getOpenId(code) {
      const _this = this;
      let params = {
        appid: _this.$store.state.appid,
        secret: _this.$store.state.secret,
        code: code,
      };
      _this.$request.getOpenid(params).then((res) => {
        if (res.data[0] && res.data[0] == 1) {
          //这里需进行页面跳转，把当前链接中的code信息给过滤掉
          const url = location.href;
          window.location.href = `${url.split("?")[0]}#${url.split("#")[1]}`;
        } else {
          const userInfo = res.data[0];
          // alert('userInfo:'+JSON.stringify(userInfo))
          const openid = userInfo.openid;
          _this.openid = openid;
          const nickname = userInfo.nickname;
          const headimgurl = userInfo.headimgurl;
          const province = userInfo.province;
          const city = userInfo.city;
          // const headimgurl = userInfo["headimgurl"];
          // const headimgurl = userInfo["headimgurl"];
          // const unionid = res.data.unionid;
          _this.$store.commit("setOpenid", openid);
          localStorage.setItem("COPENID", openid);
          // alert('COPENID:'+openid)
          const item = {
            openid,
            nickname,
            avatar: headimgurl,
            province,
            city,
            name: nickname,
          };
          _this.$store.commit("setUserInfo", item);
          localStorage.setItem("USERINFO", JSON.stringify(item));
          _this.getFansItem(item);
          _this.getPageActItem();
          _this.toCannonUrl();
        }
      });
    },
    judgeIsApply() {
      const _this = this;
      const apply_list = _this.activityItem.apply_list;
      // _this.openid = "111"
      const isApply = apply_list.some((res) => res.openid == _this.openid);
      this.activityItem.is_apply = isApply;
    },
    getPageActItem() {
      const _this = this;
      const toast = Toast.loading({
        forbidClick: true,
        message: "加载中...",
      });
      localStorage.setItem("activity_id", Number(_this.$route.params.id));
      let params = {
        activity_id: Number(_this.$route.params.id),
      };
      _this.$request.getPageActItem(params).then((res) => {
        _this.activityItem = res.data;
        // _this.activityItems = res.data;
        console.log(
          "_this.activityItem__IN___getPageActItem",
          _this.activityItem
        );
        _this.val = res.data.val;
        _this.endtime = res.data.end_time;
        setInterval(() => {
          this.timeDown(_this.endtime);
        }, 1000);
        _this.theme_color = res.data.theme_color;
        _this.introduce = res.data.introduce;
        _this.create_form = res.data.create_form;
        document.title = _this.activityItem.title;
        if (_this.activityItem) {
          _this.getOrderItem();
          _this.getActivityItem();
          _this.shareInit(_this.activityItem); // 调用微信分享的API
          document.title = _this.activityItem.title;
          _this.getInGroup();
          // _this.helpTimes(_this.activityItem);
        }
        _this.$store.commit("setActivityItem", _this.activityItem);
        toast.clear();
        _this.loadingSkeleton = false;
      });
    },
    // 获取商户
    getMerchantItem(merchant_id) {
      let params = {
        id: merchant_id,
      };
      this.$request.getMerchantItema(params).then((res) => {
        this.door_header = res.data.door_header;
        this.$store.commit("setMerchant", res.data);
      });
    },
    toCaseView() {
      window.location.href = `//${location.hostname}${
        location.href.indexOf("addons") > -1
          ? "/addons/youmi_activitys/public"
          : ""
      }/mobile/index.html`;
    },
    toView(to) {
      if (to == "applyTrue") {
        this.$router.push(`/caseShow/applyActivity/applyPZ`);
      } else {
        this.$router.push(`/caseShow/applyActivity/applyForm`);
      }
    },
    // 立即倒计时
    timeDown(time) {
      const endTime = new Date(time).getTime();
      const nowTime = new Date(time);
      var date = new Date();
      var now = date.getTime(nowTime);
      //设置截止时间
      var endDate = new Date(endTime);
      var end = endDate.getTime();
      //时间差
      var rightTime = end - now; //截止时间减去当前时间
      if (rightTime > 0) {
        //判断剩余倒计时时间如果大于0就执行倒计时否则就结束
        var dd = Math.floor(rightTime / 1000 / 60 / 60 / 24);
        var hh = Math.floor((rightTime / 1000 / 60 / 60) % 24);
        var mm = Math.floor((rightTime / 1000 / 60) % 60);
        var ss = Math.floor((rightTime / 1000) % 60);
        this.DD = dd > 9 ? dd : "0" + dd;
        this.HH = hh > 9 ? hh : "0" + hh;
        this.MM = mm > 9 ? mm : "0" + mm;
        this.SS = ss > 9 ? ss : "0" + ss;
      } else {
        this.isfail = true;
      }
    },
  },
};
</script>